<template>
  <view>
    <!-- 购物车商品列表的标题区域 -->
    <view class="cart-title">
      <!-- 左侧的图标 -->
      <uni-icons type="shop" size="18"></uni-icons>
      <!-- 描述文本 -->
      <text class="cart-title-text">购物车</text>
    </view>
    <block v-for="(goods, i) in cart" :key="i">
      <my-goods :goods="goods" :show-radio="true" @radio-change="radioChangeHandler" :show-num="true" @num-change="numberChangeHandler"></my-goods>
    </block>
  </view>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { mapState,mapMutations } from 'vuex'
  export default {
    data() {
      return {
        
      };
    },
    onLoad() {
      this.setBadge()
    },
    computed:{
      ...mapGetters('m_cart', ['total']),
      ...mapState('m_cart', ['cart']),
    },
    methods:{
      ...mapMutations('m_cart', ['updateGoodsState']),
       setBadge() {
            // 调用 uni.setTabBarBadge() 方法，为购物车设置右上角的徽标
            uni.setTabBarBadge({
              index: 2,
              text: this.total + '', // 注意：text 的值必须是字符串，不能是数字
            })
          },
           // 商品的勾选状态发生了变化
            radioChangeHandler(e) {
              console.log(e) 
              this.updateGoodsState(e)
            },
            numberChangeHandler(e){
              
            }
    }
  }
</script>

<style lang="scss">
.cart-title {
  height: 40px;
  display: flex;
  align-items: center;
  font-size: 14px;
  padding-left: 5px;
  border-bottom: 1px solid #efefef;
  .cart-title-text {
    margin-left: 10px;
  }
}
</style>
